home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / styles / CSSStyleDeclaration.as next >
Text File  |  2014-03-27  |  9KB  |  333 lines

  1. package mx.styles
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.events.EventDispatcher;
  5.    import flash.utils.Dictionary;
  6.    import mx.core.Singleton;
  7.    import mx.core.mx_internal;
  8.    import mx.managers.SystemManagerGlobals;
  9.    
  10.    use namespace mx_internal;
  11.    
  12.    public class CSSStyleDeclaration extends EventDispatcher
  13.    {
  14.       
  15.       mx_internal static const VERSION:String = "3.0.0.0";
  16.       
  17.       private static const NOT_A_COLOR:uint = 4294967295;
  18.       
  19.       private static const FILTERMAP_PROP:String = "__reserved__filterMap";
  20.        
  21.       
  22.       mx_internal var effects:Array;
  23.       
  24.       protected var overrides:Object;
  25.       
  26.       public var defaultFactory:Function;
  27.       
  28.       public var factory:Function;
  29.       
  30.       mx_internal var selectorRefCount:int = 0;
  31.       
  32.       private var styleManager:IStyleManager2;
  33.       
  34.       private var clones:Dictionary;
  35.       
  36.       public function CSSStyleDeclaration(param1:String = null)
  37.       {
  38.          clones = new Dictionary(true);
  39.          super();
  40.          if(param1)
  41.          {
  42.             styleManager = Singleton.getInstance("mx.styles::IStyleManager2") as IStyleManager2;
  43.             styleManager.setStyleDeclaration(param1,this,false);
  44.          }
  45.       }
  46.       
  47.       mx_internal function addStyleToProtoChain(param1:Object, param2:DisplayObject, param3:Object = null) : Object
  48.       {
  49.          var p:String = null;
  50.          var emptyObjectFactory:Function = null;
  51.          var filteredChain:Object = null;
  52.          var filterObjectFactory:Function = null;
  53.          var i:String = null;
  54.          var chain:Object = param1;
  55.          var target:DisplayObject = param2;
  56.          var filterMap:Object = param3;
  57.          var nodeAddedToChain:Boolean = false;
  58.          var originalChain:Object = chain;
  59.          if(filterMap)
  60.          {
  61.             chain = {};
  62.          }
  63.          if(defaultFactory != null)
  64.          {
  65.             defaultFactory.prototype = chain;
  66.             chain = new defaultFactory();
  67.             nodeAddedToChain = true;
  68.          }
  69.          if(factory != null)
  70.          {
  71.             factory.prototype = chain;
  72.             chain = new factory();
  73.             nodeAddedToChain = true;
  74.          }
  75.          if(overrides)
  76.          {
  77.             if(defaultFactory == null && factory == null)
  78.             {
  79.                emptyObjectFactory = function():void
  80.                {
  81.                };
  82.                emptyObjectFactory.prototype = chain;
  83.                chain = new emptyObjectFactory();
  84.                nodeAddedToChain = true;
  85.             }
  86.             for(p in overrides)
  87.             {
  88.                if(overrides[p] === undefined)
  89.                {
  90.                   delete chain[p];
  91.                }
  92.                else
  93.                {
  94.                   chain[p] = overrides[p];
  95.                }
  96.             }
  97.          }
  98.          if(filterMap)
  99.          {
  100.             if(nodeAddedToChain)
  101.             {
  102.                filteredChain = {};
  103.                filterObjectFactory = function():void
  104.                {
  105.                };
  106.                filterObjectFactory.prototype = originalChain;
  107.                filteredChain = new filterObjectFactory();
  108.                for(i in chain)
  109.                {
  110.                   if(filterMap[i] != null)
  111.                   {
  112.                      filteredChain[filterMap[i]] = chain[i];
  113.                   }
  114.                }
  115.                chain = filteredChain;
  116.                chain[FILTERMAP_PROP] = filterMap;
  117.             }
  118.             else
  119.             {
  120.                chain = originalChain;
  121.             }
  122.          }
  123.          if(nodeAddedToChain)
  124.          {
  125.             clones[chain] = 1;
  126.          }
  127.          return chain;
  128.       }
  129.       
  130.       public function getStyle(param1:String) : *
  131.       {
  132.          var _loc2_:* = undefined;
  133.          var _loc3_:* = undefined;
  134.          if(overrides)
  135.          {
  136.             if(param1 in overrides && overrides[param1] === undefined)
  137.             {
  138.                return undefined;
  139.             }
  140.             _loc3_ = overrides[param1];
  141.             if(_loc3_ !== undefined)
  142.             {
  143.                return _loc3_;
  144.             }
  145.          }
  146.          if(factory != null)
  147.          {
  148.             factory.prototype = {};
  149.             _loc2_ = new factory();
  150.             _loc3_ = _loc2_[param1];
  151.             if(_loc3_ !== undefined)
  152.             {
  153.                return _loc3_;
  154.             }
  155.          }
  156.          if(defaultFactory != null)
  157.          {
  158.             defaultFactory.prototype = {};
  159.             _loc2_ = new defaultFactory();
  160.             _loc3_ = _loc2_[param1];
  161.             if(_loc3_ !== undefined)
  162.             {
  163.                return _loc3_;
  164.             }
  165.          }
  166.          return undefined;
  167.       }
  168.       
  169.       public function clearStyle(param1:String) : void
  170.       {
  171.          setStyle(param1,undefined);
  172.       }
  173.       
  174.       public function setStyle(param1:String, param2:*) : void
  175.       {
  176.          var _loc7_:int = 0;
  177.          var _loc8_:Object = null;
  178.          var _loc3_:Object = getStyle(param1);
  179.          var _loc4_:Boolean = false;
  180.          if(mx_internal::selectorRefCount > 0 && factory == null && defaultFactory == null && !overrides && _loc3_ !== param2)
  181.          {
  182.             _loc4_ = true;
  183.          }
  184.          if(param2 !== undefined)
  185.          {
  186.             setStyle(param1,param2);
  187.          }
  188.          else
  189.          {
  190.             if(param2 == _loc3_)
  191.             {
  192.                return;
  193.             }
  194.             setStyle(param1,param2);
  195.          }
  196.          var _loc5_:Array;
  197.          var _loc6_:int = (_loc5_ = SystemManagerGlobals.topLevelSystemManagers).length;
  198.          if(_loc4_)
  199.          {
  200.             _loc7_ = 0;
  201.             while(_loc7_ < _loc6_)
  202.             {
  203.                (_loc8_ = _loc5_[_loc7_]).regenerateStyleCache(true);
  204.                _loc7_++;
  205.             }
  206.          }
  207.          _loc7_ = 0;
  208.          while(_loc7_ < _loc6_)
  209.          {
  210.             (_loc8_ = _loc5_[_loc7_]).notifyStyleChangeInChildren(param1,true);
  211.             _loc7_++;
  212.          }
  213.       }
  214.       
  215.       private function clearStyleAttr(param1:String) : void
  216.       {
  217.          var _loc2_:* = undefined;
  218.          if(!overrides)
  219.          {
  220.             overrides = {};
  221.          }
  222.          overrides[param1] = undefined;
  223.          for(_loc2_ in clones)
  224.          {
  225.             delete _loc2_[param1];
  226.          }
  227.       }
  228.       
  229.       mx_internal function createProtoChainRoot() : Object
  230.       {
  231.          var _loc1_:Object = {};
  232.          if(defaultFactory != null)
  233.          {
  234.             defaultFactory.prototype = _loc1_;
  235.             _loc1_ = new defaultFactory();
  236.          }
  237.          if(factory != null)
  238.          {
  239.             factory.prototype = _loc1_;
  240.             _loc1_ = new factory();
  241.          }
  242.          clones[_loc1_] = 1;
  243.          return _loc1_;
  244.       }
  245.       
  246.       mx_internal function clearOverride(param1:String) : void
  247.       {
  248.          if(overrides && overrides[param1])
  249.          {
  250.             delete overrides[param1];
  251.          }
  252.       }
  253.       
  254.       mx_internal function setStyle(param1:String, param2:*) : void
  255.       {
  256.          var _loc3_:Object = null;
  257.          var _loc4_:* = undefined;
  258.          var _loc5_:Number = NaN;
  259.          var _loc6_:Object = null;
  260.          if(param2 === undefined)
  261.          {
  262.             clearStyleAttr(param1);
  263.             return;
  264.          }
  265.          if(param2 is String)
  266.          {
  267.             if(!styleManager)
  268.             {
  269.                styleManager = Singleton.getInstance("mx.styles::IStyleManager2") as IStyleManager2;
  270.             }
  271.             if((_loc5_ = styleManager.getColorName(param2)) != NOT_A_COLOR)
  272.             {
  273.                param2 = _loc5_;
  274.             }
  275.          }
  276.          if(defaultFactory != null)
  277.          {
  278.             _loc3_ = new defaultFactory();
  279.             if(_loc3_[param1] !== param2)
  280.             {
  281.                if(!overrides)
  282.                {
  283.                   overrides = {};
  284.                }
  285.                overrides[param1] = param2;
  286.             }
  287.             else if(overrides)
  288.             {
  289.                delete overrides[param1];
  290.             }
  291.          }
  292.          if(factory != null)
  293.          {
  294.             _loc3_ = new factory();
  295.             if(_loc3_[param1] !== param2)
  296.             {
  297.                if(!overrides)
  298.                {
  299.                   overrides = {};
  300.                }
  301.                overrides[param1] = param2;
  302.             }
  303.             else if(overrides)
  304.             {
  305.                delete overrides[param1];
  306.             }
  307.          }
  308.          if(defaultFactory == null && factory == null)
  309.          {
  310.             if(!overrides)
  311.             {
  312.                overrides = {};
  313.             }
  314.             overrides[param1] = param2;
  315.          }
  316.          for(_loc4_ in clones)
  317.          {
  318.             if(_loc6_ = _loc4_[FILTERMAP_PROP])
  319.             {
  320.                if(_loc6_[param1] != null)
  321.                {
  322.                   _loc4_[_loc6_[param1]] = param2;
  323.                }
  324.             }
  325.             else
  326.             {
  327.                _loc4_[param1] = param2;
  328.             }
  329.          }
  330.       }
  331.    }
  332. }
  333.